{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Importing Libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from faker import Faker\n",
    "import random\n",
    "from random import randint\n",
    "import csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Data Generator Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def datagen(np, parameters):\n",
    "    fake = Faker()\n",
    "    with open(\"Data_generator.csv\", 'wt', newline='') as csvFile:\n",
    "        writer = csv.DictWriter(csvFile, fieldnames=parameters)\n",
    "        writer.writeheader() \n",
    "        for i in range(np):\n",
    "            ph1=str(random.randint(0,999))\n",
    "            ph2=str(random.randint(0,999)).zfill(3)\n",
    "            ph3=str(random.randint(0,9999)).zfill(4)\n",
    "            phone_number=\"{}-{}-{}\".format(ph1,ph2,ph3)\n",
    "            \n",
    "            writer.writerow({\n",
    "                \"Student Name\": fake.name(),\n",
    "                \"Country\": fake.country(),\n",
    "                \"Course Comments\": fake.text(),\n",
    "                \"Student ID\": randint(1, 99999),\n",
    "                \"Email Id\": fake.email(),\n",
    "                \"Phone Number\": phone_number,\n",
    "                \"Date of Birth\": random.randint(1950,2010),\n",
    "                \"House Address\": fake.address(),\n",
    "                \"Latitude\": fake.latitude(),\n",
    "                \"Longitude\": fake.longitude()\n",
    "            })          "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Function Call"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Enter Number of Student Data:50\n",
      "File saved.\n"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    np = int(input(\" Enter Number of Student Data:\"))\n",
    "    parameters = [\"Student ID\", \"Student Name\", \"Email Id\", \"Phone Number\", \"Date of Birth\", \"House Address\",\n",
    "               \"Latitude\", \"Longitude\", \"Country\", \"Course Comments\"]\n",
    "    datagen(np, parameters)\n",
    "    print(\"File saved.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6rc1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
